---
title: "Cleaning Pew Religious Belief and National Belonging in Central and Eastern Europe"
---

# Load

```{r}
# load packages
  source("helper-packages.R")

# load second european union minorities and discrimination survey
  prbnbcee_raw <- 
    read_sav("../raw-data/y-multi-pew-religious-belief-and -national-belonging-in-central-and-eastern-europe/Eastern Europe Public Data_12.5 CHECKED.sav")
```

# Clean

Dates are missing for Kazakhstan. Data is provided from the region, but no fieldwork dates are provided in the documentation. Impute Kazakhstand dates using the maximum and minumum of all other dates for this survey.

```{r}
# declare dates
  prbnbcee_dates <- 
    tribble(
      ~resp_country_common, ~resp_interview_start_date, ~resp_interview_end_date,
      "Armenia", "Jun. 29, 2015", "Dec. 14, 2015",
      "Belarus", "Jul. 3, 2015", "Aug. 1, 2015",
      "Bosnia", "Jun. 27, 2015", "Feb. 26, 2016",
      "Bulgaria", "Jul. 1, 2015", "Oct. 18, 2015",
      "Croatia", "Jul. 8, 2015", "Feb. 21, 2016",
      "Czechia", "Jul. 4, 2015", "Nov. 30, 2015",
      "Estonia", "Jun. 29, 2015", "Mar. 31, 2016",
      "Georgia", "Mar. 29, 2016", "Apr. 28, 2016",
      "Greece", "Jun. 27, 2015", "Nov. 28, 2015",
      "Hungary", "Jul. 1, 2015", "Feb. 26, 2016",
      "Kazakhstan", "Jun. 27, 2015", "Jun. 1, 2016", # imputed: max(prbnbcee_dates$resp_interview_start_date, na.rm = T)
      "Latvia", "Jun. 1, 2016", "Jul. 24, 2016",
      "Lithuania", "Jul. 13, 2015", "Jan. 20, 2016",
      "Moldova", "Jul. 4, 2015", "Aug. 2, 2015",
      "Poland", "Jun. 30, 2015", "Nov. 8, 2015",
      "Romania", "Jul. 1, 2015", "Oct. 18, 2015",
      "Russia", "Jul. 1, 2015", "Jul. 31, 2016",
      "Serbia", "Jun. 27, 2015", "Dec. 29, 2015",
      "Ukraine", "Jul. 3, 2015", "Jul. 29, 2015") %>% 
    mutate(
      resp_interview_start_date = as.Date(resp_interview_start_date, "%b. %d, %Y"),
      resp_interview_end_date = as.Date(resp_interview_end_date, "%b. %d, %Y"))

# clean
  clean_prbnbcee <- 
    prbnbcee_raw %>% 
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Pew Religious Belief and National Belonging in Central and Eastern Europe",
    
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "pewrsr.ch/3NFXHyj",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = to_character(COUNTRY),

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),

     # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA) %>% 
        left_join(
          prbnbcee_dates, by = "resp_country_common") %>% 
        mutate(      
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # for religion: covert to characterized attributes
        across(starts_with("qcurrel", ignore.case = F), ~ to_character(.)),
    
      # merge religion variables into one variable 
        religion_temp1 = 
          case_when(
                resp_country_common == "Armenia" ~ qcurrelarmrec,
                resp_country_common == "Belarus" ~ qcurrelbelrec,
                resp_country_common == "Bosnia" ~ qcurrelbosrec,
                resp_country_common == "Bulgaria" ~ qcurrelbulrec,
                resp_country_common == "Croatia" ~ qcurrelcrorec,
                resp_country_common == "Czechia" ~ qcurrelczerec,
                resp_country_common == "Estonia" ~ qcurrelestrec,
                resp_country_common == "Georgia" ~ qcurrelgeorec,
                resp_country_common == "Greece" ~ qcurrelgrerec,
                resp_country_common == "Hungary" ~ qcurrelhunrec,
                resp_country_common == "Kazakhstan" ~ qcurrelkazrec,
                resp_country_common == "Latvia" ~ qcurrellatrec,
                resp_country_common == "Lithuania" ~ qcurrellitrec,
                resp_country_common == "Moldova" ~ qcurrelmolrec,
                resp_country_common == "Poland" ~ qcurrelpolrec,
                resp_country_common == "Romania" ~ qcurrelromrec,
                resp_country_common == "Russia" ~ qcurrelrusrec,
                resp_country_common == "Serbia" ~ qcurrelserrec,
                resp_country_common == "Ukraine" ~ qcurrelukrrec),
    
      # perform the recodes
        resp_religion = 
          case_when(
            religion_temp1 == "Christian" ~ "Christian",                               
            religion_temp1 == "Something else/other" ~ "Other religion",                 
            religion_temp1 == "Atheist" ~ NA_character_,                
            religion_temp1 == "Don't know (DO NOT READ)" ~ NA_character_,              
            religion_temp1 == "Jewish" ~ "Jewish",               
            religion_temp1 == "Refused (DO NOT READ)" ~ NA_character_,                
            religion_temp1 == "Nothing in particular" ~ NA_character_,                    
            religion_temp1 == "Muslim" ~ "Muslim",                                 
            religion_temp1 == "Agnostic" ~ NA_character_,                                 
            religion_temp1 == "Old believer/old ritualist" ~ "Other religion",              
            religion_temp1 == "Ancient religion or traditional religion" ~ "Other religion", 
            religion_temp1 == "Soemthing else/other" ~ "Other religion",                    
            religion_temp1 == "Buddhist" ~ "Buddhist"),

      # for denomination: covert to characterized attributes
        across(starts_with("qdenom", ignore.case = F), ~ to_character(.)),

      # merge religion variables into one variable 
        resp_denomination = 
          case_when(
            resp_country_common == "Armenia" ~ qdenomarmrec,
            resp_country_common == "Belarus" ~ qdenombelrec,
            resp_country_common == "Bosnia" ~ qdenombosrec,
            resp_country_common == "Bulgaria" ~ qdenombulrec,
            resp_country_common == "Croatia" ~ qdenomcrorec,
            resp_country_common == "Czechia" ~ qdenomczerec,
            resp_country_common == "Estonia" ~ qdenomestrec,
            resp_country_common == "Georgia" ~ qdenomgeorec,
            resp_country_common == "Greece" ~ qdenomgrerec,
            resp_country_common == "Hungary" ~ qdenomhunrec,
            resp_country_common == "Kazakhstan" ~ qdenomkazrec,
            resp_country_common == "Latvia" ~ qdenomlatrec,
            resp_country_common == "Lithuania" ~ qdenomlitrec,
            resp_country_common == "Moldova" ~ qdenommolrec,
            resp_country_common == "Poland" ~ qdenompolrec,
            resp_country_common == "Romania" ~ qdenomromrec,
            resp_country_common == "Russia" ~ qdenomrusrec,
            resp_country_common == "Serbia" ~ qdenomserrec,
            resp_country_common == "Ukraine" ~ qdenomukrrec),

      # fix errors in resp_religion based on values in resp_denomination    
        resp_religion = 
          case_when(
            str_detect(resp_denomination, "Catholic|Lutheran|Baptist|Christian|Presbyterian|Orthodox") ~ "Christian",
            TRUE ~ resp_religion),
    
      # ensure that orthodox and roman catholic are standard in denomination (as these are Q-targets)    
        resp_denomination = 
          case_when(
            str_detect(resp_denomination, "Orthodox") ~ "Orthodox",
            str_detect(resp_denomination, "Catholic") ~ "Roman Catholic",
            TRUE ~ resp_denomination),
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age =
          dplyr::recode(
            as.character(QAGE),
            "97" = "97+",
            "98" = NA_character_,
            "99" = NA_character_),        
      
    # respondent's education level
        resp_education_original =
          case_when(
            as.character(QEDU1ARM) == "1" ~ "1. No primary (including illiterate) [No education]",
            as.character(QEDU1ARM) == "2" ~ "2. Primary (3 years) [Primary]", # difficult call but assume this means completed
            as.character(QEDU1ARM) == "3" ~ "3. Basic (9 years) [Primary]",
            as.character(QEDU1ARM) == "4" ~ "4. General (Secondary) (10-12 years) [Primary]",
            as.character(QEDU1ARM) == "5" ~ "5. Primary vocational [Primary]",
            as.character(QEDU1ARM) == "6" ~ "6. Middle (secondary) vocational [Primary]",
            as.character(QEDU1ARM) == "7" ~ "7. Complete higher (at least 3 years) [College]",
            as.character(QEDU1ARM) == "8" ~ "8. Post graduate and higher professional [College]",
            as.character(QEDU1ARM) == "9" ~ "9. Scientific degree [College]",
            
            as.character(QEDU1BEL) == "1" ~ "1. Primary general education or less/ no formal education [Primary]",
            as.character(QEDU1BEL) == "2" ~ "2. 5-9 grades of secondary school (incomplete secondary) [Primary]",
            as.character(QEDU1BEL) == "3" ~ "3. Completed secondary education [Primary]",
            as.character(QEDU1BEL) == "4" ~ "4. Primary professional education [Primary]",
            as.character(QEDU1BEL) == "5" ~ "5. Secondary professional education [Primary]",
            as.character(QEDU1BEL) == "6" ~ "6. Higher education on 1-tier system [Primary]",
            as.character(QEDU1BEL) == "7" ~ "7. Bachelor's degree [College]",
            as.character(QEDU1BEL) == "8" ~ "8. Master's degree [College]",
            as.character(QEDU1BEL) == "9" ~ "9. Academic degree [College]",
            
            as.character(QEDU1BOS) == "1" ~ "1. No school (up to four grades) [No education]",
            as.character(QEDU1BOS) == "2" ~ "2. Incomplete primary school (grades 4-7) [No education]",
            as.character(QEDU1BOS) == "3" ~ "3. Completed primary school (grade 8) [Primary]",
            as.character(QEDU1BOS) == "4" ~ "4. Secondary vocational 1-2 years [Primary]",
            as.character(QEDU1BOS) == "5" ~ "5. Secondary vocational 3 years [Primary]",
            as.character(QEDU1BOS) == "6" ~ "6. Secondary vocational 4 years [Primary]",
            as.character(QEDU1BOS) == "7" ~ "7. Secondary orientation (1978-1988) [Primary]",
            as.character(QEDU1BOS) == "8" ~ "8. Secondary general (grammar school) [Primary]",
            as.character(QEDU1BOS) == "9" ~ "9. Higher schools [Primary]",
            as.character(QEDU1BOS) == "10" ~ "10. University: undergraduate studies - Natural and technical sciences [College]",
            as.character(QEDU1BOS) == "11" ~ "11. University: undergraduate studies - Social sciences [College]",
            as.character(QEDU1BOS) == "12" ~ "12. University: undergraduate studies - Art Academy [College]",
            as.character(QEDU1BOS) == "13" ~ "13. Specialized professional studies [College]",
            as.character(QEDU1BOS) == "14" ~ "14. Specialized academic studies [College]",
            as.character(QEDU1BOS) == "15" ~ "15. University: completed artistic or scientific postgraduate program - Magistrature or Master [College]",
            as.character(QEDU1BOS) == "16" ~ "16. Ph.D Obtained [College]",
            
            as.character(QEDU1BUL) == "1" ~ "1. Not completed primery education [No education]",
            as.character(QEDU1BUL) == "2" ~ "2. Primary [Primary]",
            as.character(QEDU1BUL) == "3" ~ "3. Lower secondary [Primary]",
            as.character(QEDU1BUL) == "4" ~ "4. Upper secondary general [Primary]",
            as.character(QEDU1BUL) == "5" ~ "5. Upper secondary specialized general - foreign language and science high schools [Primary]",
            as.character(QEDU1BUL) == "6" ~ "6. Upper secondary education in schools on arts and sports [Primary]",
            as.character(QEDU1BUL) == "7" ~ "7. Upper secondary professional [Primary]",
            as.character(QEDU1BUL) == "8" ~ "8. Semi-higher [Primary]",
            as.character(QEDU1BUL) == "9" ~ "9. College [Primary]", # assuming this isn't a completed BA
            as.character(QEDU1BUL) == "10" ~ "10. Higher/ Bachelor's degree [College]",
            as.character(QEDU1BUL) == "11" ~ "11. Higher/Master's degree [College]",
            as.character(QEDU1BUL) == "12" ~ "12. PhD [College]",
            
            as.character(QEDU1CRO) == "1" ~ "1. No school (three grade) [No education]",
            as.character(QEDU1CRO) == "2" ~ "2. Incomplete primary school (grades 4-7) [No education]",
            as.character(QEDU1CRO) == "3" ~ "3. Completed primary school [Primary]",
            as.character(QEDU1CRO) == "4" ~ "4. Vocational training lasting 1-2 years (Trade, Industry, KV) [Primary]",
            as.character(QEDU1CRO) == "5" ~ "5. Vocational School for 3 years (craft, industrial, skilled) [Primary]",
            as.character(QEDU1CRO) == "6" ~ "6. Technical and related professional schools, Vocational schools for a period of 4 years or more [Primary]",
            as.character(QEDU1CRO) == "7" ~ "7. Gymnasium [Primary]",
            as.character(QEDU1CRO) == "8" ~ "8. Expert studies on high school or college (2-3 years) [Primary]",
            as.character(QEDU1CRO) == "9" ~ "9. Undergraduate study - the academic title of 'Bachelor' (3-4 years): Art Academy (undergraduate studies) [College]",
            as.character(QEDU1CRO) == "10" ~ "10. Graduate professional studies (4-5 years), specialist in the field [College]",
            as.character(QEDU1CRO) == "11" ~ "11. Graduate studies (4-6 years old) - the old program [College]",
            as.character(QEDU1CRO) == "12" ~ "12. Professional Master's Degree (5 years): Arts Academy (graduate) [College]",
            as.character(QEDU1CRO) == "13" ~ "13. Reached completed master's degree or post-graduate master degree [College]",
            as.character(QEDU1CRO) == "14" ~ "14. Reached Ph.D [College]",
            
            as.character(QEDU1CZE) == "1" ~ "1. No education [No education]",
            as.character(QEDU1CZE) == "2" ~ "2. Incomplete primary education [No education]",
            as.character(QEDU1CZE) == "3" ~ "3. Primary education [Primary]",
            as.character(QEDU1CZE) == "4" ~ "4. Central inc. apprenticeship (school) [Primary]",
            as.character(QEDU1CZE) == "5" ~ "5. Secondary vocational (with GCSE) [Primary]",
            as.character(QEDU1CZE) == "6" ~ "6. full secondary vocational (with GCSE) [Primary]",
            as.character(QEDU1CZE) == "7" ~ "7. up studies (incl. post-secondary studies) [Primary]",
            as.character(QEDU1CZE) == "8" ~ "8. higher professional education (graduation) [Primary]",
            as.character(QEDU1CZE) == "9" ~ "9. Bachelor (Bc., BcA.) [College]",
            as.character(QEDU1CZE) == "10" ~ "10. Master (Ing., MD., Mgr., Mgr., Mgr., etc.). [College]",
            as.character(QEDU1CZE) == "11" ~ "11. Doctoral (Ph.D., ThD., DSc. and others. ) [College]",
            
            as.character(QEDU1EST) == "1" ~ "1. No education (below 4 grades) [No education]",
            as.character(QEDU1EST) == "2" ~ "2. Finished primary education (grades 4-6) [Primary]",
            as.character(QEDU1EST) == "3" ~ "3. Vocational education without primary education [Primary]",
            as.character(QEDU1EST) == "4" ~ "4. Finished basic education (grades 7-9) [Primary]",
            as.character(QEDU1EST) == "5" ~ "5. Vocational education based on basic education (Program less than 2 years) [Primary]",
            as.character(QEDU1EST) == "6" ~ "6. Finished secondary education [Primary]",
            as.character(QEDU1EST) == "7" ~ "7. Vocational education based on basic education (Program over 2 years)) [Primary]",
            as.character(QEDU1EST) == "8" ~ "8. Vocational education with secondary education or specialized education/technical education after basic education [Primary]",
            as.character(QEDU1EST) == "9" ~ "9. Vocational education based on secondary education, specialized education or vocational secondary education based on seco [Primary]",
            as.character(QEDU1EST) == "10" ~ "10. Studies of vocational higher education or professional higher education based on secondary education (up to 2 years, but  [Primary]",
            as.character(QEDU1EST) == "11" ~ "11. Vocational higher education, professional higher education or bachelors degree (3-4 years of studies) [Primary]",
            as.character(QEDU1EST) == "12" ~ "12. University Bachelor's degree (3-4 years of studies) [College]",
            as.character(QEDU1EST) == "13" ~ "13. Master's degree from a University of applied sciences [College]",
            as.character(QEDU1EST) == "14" ~ "14. Master's degree (using the 3+2, 4+2 or 5+4 system, including Integrated Bachelor 's and Master's Study), higher educatio [College]",
            as.character(QEDU1EST) == "15" ~ "15. Doctorate (including Candidate's degree) [College]",
            
            as.character(QEDU1GEO) == "1" ~ "1. Primary general education or less/ no formal education [Primary]",
            as.character(QEDU1GEO) == "2" ~ "2. 5-9 grades of secondary school (incomplete secondary) [Primary]",
            as.character(QEDU1GEO) == "3" ~ "3. Completed secondary education [Primary]",
            as.character(QEDU1GEO) == "4" ~ "4. Primary professional education [Primary]",
            as.character(QEDU1GEO) == "5" ~ "5. Secondary professional education [Primary]",
            as.character(QEDU1GEO) == "6" ~ "6. Higher education on 1-tier system [Primary]",
            as.character(QEDU1GEO) == "7" ~ "7. Bachelor's degree [College]",
            as.character(QEDU1GEO) == "8" ~ "8. Master's degree [College]",
            as.character(QEDU1GEO) == "9" ~ "9. Academic degree [College]",
            
            as.character(QEDU1GRE) == "1" ~ "1. Didnt go to school,  Kindergarden, primary education unfinished [No education]",
            as.character(QEDU1GRE) == "2" ~ "2. Primary school leaving certificate [Primary]",
            as.character(QEDU1GRE) == "3" ~ "3. Certificate of 3 grades Gymnasium-Middle School [Primary]",
            as.character(QEDU1GRE) == "4" ~ "4. Certificate of Technical Vocational Educational High School (EPAL) , Certificate of Technical Vocational School (EPAS) [Primary]",
            as.character(QEDU1GRE) == "5" ~ "5. Certificate of Unified General Lyceum-High school [Primary]",
            as.character(QEDU1GRE) == "6" ~ "6. Institute of vocational training (IEK) [Primary]",
            as.character(QEDU1GRE) == "7" ~ "7. Technological Educational Institute (T.E.I.) , (Higher tetriary education), Higher Professional Education (before they b [Primary]",
            as.character(QEDU1GRE) == "8" ~ "8. Highest Technological Educational Institute (A.T.E.I.) , (Highest tetriary education), Highest Professional Education (a [Primary]",
            as.character(QEDU1GRE) == "9" ~ "9. University, Technical University, Greek Open University (EAP)  (Highest tetriary education)  (BA or BSc) [College]",
            as.character(QEDU1GRE) == "10" ~ "10. University: undergraduate studies - Natural and technical sciences [College]",
            as.character(QEDU1GRE) == "11" ~ "11. University, Technical University, Greek Open University (EAP)  (Highest tetriary education)  (Doctorate /Ph.D)s [College]",
            
            as.character(QEDU1HUN) == "1" ~ "1. has not attended school [No education]",
            as.character(QEDU1HUN) == "2" ~ "2. 1th-7th grades of primary school or the equivalent [No education]",
            as.character(QEDU1HUN) == "3" ~ "3. completed primary education or the equivalent [Primary]",
            as.character(QEDU1HUN) == "4" ~ "4. apprenticeship, vocational school [Primary]",
            as.character(QEDU1HUN) == "5" ~ "5. matriculation, completed secondary vocational training [Primary]",
            as.character(QEDU1HUN) == "6" ~ "6. matriculation, completed grammar school [Primary]",
            as.character(QEDU1HUN) == "7" ~ "7. vocational training based on matriculation without access to higher education, secondary technical school [Primary]",
            as.character(QEDU1HUN) == "8" ~ "8. accredited post secondary training, higher technical school [Primary]",
            as.character(QEDU1HUN) == "9" ~ "9. college degree or college bachelor degree - BA/BSc [College]",
            as.character(QEDU1HUN) == "10" ~ "10. university degree or university master degree - MA/MSc [College]",
            as.character(QEDU1HUN) == "11" ~ "11. doctoral degree [College]",
            
            as.character(QEDU1KAZ) == "1" ~ "1. Primary general education or less/ no formal education [Primary]",
            as.character(QEDU1KAZ) == "2" ~ "2. 5-9 grades of secondary school (incomplete secondary) [Primary]",
            as.character(QEDU1KAZ) == "3" ~ "3. Completed secondary education [Primary]",
            as.character(QEDU1KAZ) == "4" ~ "4. Primary professional education [Primary]",
            as.character(QEDU1KAZ) == "5" ~ "5. Secondary professional education [Primary]",
            as.character(QEDU1KAZ) == "6" ~ "6. Higher education on 1-tier system [Primary]",
            as.character(QEDU1KAZ) == "7" ~ "7. Bachelor's degree [College]",
            as.character(QEDU1KAZ) == "8" ~ "8. Master's degree [College]",
            as.character(QEDU1KAZ) == "9" ~ "9. Academic degree [College]",
            
            as.character(QEDU1LAT) == "1" ~ "1. Incomplete primary education [No education]",
            as.character(QEDU1LAT) == "2" ~ "2. Primary education (4-8 grades before 1990, 4-9 grades after [Primary]",
            as.character(QEDU1LAT) == "3" ~ "3. Technical study (on the base on 8 grades of general school b [Primary]",
            as.character(QEDU1LAT) == "4" ~ "4. Completed general secondary education [Primary]",
            as.character(QEDU1LAT) == "5" ~ "5. Secondary professional education  (on the base on 8 grades o [Primary]",
            as.character(QEDU1LAT) == "6" ~ "6. Secondary professional education  (on the base on 11 grades [Primary]",
            as.character(QEDU1LAT) == "7" ~ "7. 3-4 years in high school (bachelor degree after 1990) [Primary]",
            as.character(QEDU1LAT) == "8" ~ "8. Higher education (completed high education before 1990 and c [College]", # ambiguous
            as.character(QEDU1LAT) == "9" ~ "9. Academic degree [College]",
            
            as.character(QEDU1LIT) == "1" ~ "1. Unfinished primary [No education]",
            as.character(QEDU1LIT) == "2" ~ "2. Primary [Primary]",
            as.character(QEDU1LIT) == "3" ~ "3. Vocational acquired completed basic education [Primary]",
            as.character(QEDU1LIT) == "4" ~ "4. Home education (includes youth, evening schools) [Primary]",
            as.character(QEDU1LIT) == "5" ~ "5. Vocational acquired together and completing basic education [Primary]",
            as.character(QEDU1LIT) == "6" ~ "6. Professional, acquired after completion of basic education (in the vocational training program lasted less than two year [Primary]",
            as.character(QEDU1LIT) == "7" ~ "7. Professional, acquired after completion of basic education (in the vocational training program lasted for two years or m [Primary]",
            as.character(QEDU1LIT) == "8" ~ "8. High school (includes gymnasiums, lyceum, evening schools) [Primary]",
            as.character(QEDU1LIT) == "9" ~ "9. Professional, acquired after completion of basic education, while acquiring and secondary education [Primary]",
            as.character(QEDU1LIT) == "10" ~ "10. Professional, acquired after completion of secondary education [Primary]",
            as.character(QEDU1LIT) == "11" ~ "11. College or special secondary, acquired after completion of basic education (includes technicums if join post-basic educa [Primary]",
            as.character(QEDU1LIT) == "12" ~ "12. College or special secondary, acquired after completion of secondary education (including technical colleges and if join [Primary]",
            as.character(QEDU1LIT) == "13" ~ "13. College [Primary]",
            as.character(QEDU1LIT) == "14" ~ "14. University degree, acquired after completion of undergraduate studies [College]",
            as.character(QEDU1LIT) == "15" ~ "15. University degree obtained at the end integrated (including studies in higher education to reform 1991-1992.) Or special [College]",
            as.character(QEDU1LIT) == "16" ~ "16. University degree, acquired after completion of a Master's or residency studies [College]",
            as.character(QEDU1LIT) == "17" ~ "17. PhD candidate or degree [College]",
            
            as.character(QEDU1MOL) == "1" ~ "1. Primary general education or less/ no formal education [Primary]",
            as.character(QEDU1MOL) == "2" ~ "2. 5-9 grades of secondary school (incomplete secondary) [Primary]",
            as.character(QEDU1MOL) == "3" ~ "3. Completed secondary education [Primary]",
            as.character(QEDU1MOL) == "4" ~ "4. Completed Lyceum (12 grades) [Primary]",
            as.character(QEDU1MOL) == "5" ~ "5. Primary professional education [Primary]",
            as.character(QEDU1MOL) == "6" ~ "6. Secondary professional education [Primary]",
            as.character(QEDU1MOL) == "7" ~ "7. Higher education on 1-tier system [Primary]",
            as.character(QEDU1MOL) == "8" ~ "8. Completed college (2-tier system) [College]",
            as.character(QEDU1MOL) == "9" ~ "9. Master's degree [College]",
            as.character(QEDU1MOL) == "10"~ "10. Academic degree [College]",
            
            as.character(QEDU1POL) == "1" ~ "1. No formal education or incomplete primary [No education]",
            as.character(QEDU1POL) == "2" ~ "2. Primary - 6 classes [Primary]",
            as.character(QEDU1POL) == "3" ~ "3. Lower secondary or primary - 8 classes [Primary]",
            as.character(QEDU1POL) == "4" ~ "4. Basic vocational education [Primary]",
            as.character(QEDU1POL) == "5" ~ "5. Upper secondary general or technical education [Primary]",
            as.character(QEDU1POL) == "6" ~ "6. Post-upper secondary non-tertiary education [Primary]",
            as.character(QEDU1POL) == "7" ~ "7. Higher professional education with bachelor's degree [College]",
            as.character(QEDU1POL) == "8" ~ "8. University education (eq. master degree) [College]",
            as.character(QEDU1POL) == "9" ~ "9. PhD [College]",
            as.character(QEDU1POL) == "10" ~ "10. Incomplete basic vocational education [Primary]",
            as.character(QEDU1POL) == "11" ~ "11. Incomplete upper secondary education [Primary]",
            as.character(QEDU1POL) == "12" ~ "12. Incomplete Masters [College]", # odd placement
            
            as.character(QEDU1ROM) == "1" ~ "1. Without education [No education]",
            as.character(QEDU1ROM) == "2" ~ "2. Incomplete primary [No education]",
            as.character(QEDU1ROM) == "3" ~ "3. Primary [Primary]",
            as.character(QEDU1ROM) == "4" ~ "4. Incomplete Gymnazium [Primary]",
            as.character(QEDU1ROM) == "5" ~ "5. Gymnazium [Primary]",
            as.character(QEDU1ROM) == "6" ~ "6. Vocational school [Primary]",
            as.character(QEDU1ROM) == "7" ~ "7. Incomplete High school [Primary]",
            as.character(QEDU1ROM) == "8" ~ "8. High school [Primary]",
            as.character(QEDU1ROM) == "9" ~ "9. Post highschool [Primary]",
            as.character(QEDU1ROM) == "10" ~ "10. Foreman school [Primary]",
            as.character(QEDU1ROM) == "11" ~ "11. Incomplete university [Primary]",
            as.character(QEDU1ROM) == "12" ~ "12. University/college [College]",
            as.character(QEDU1ROM) == "13" ~ "13. University [College]",
            as.character(QEDU1ROM) == "14" ~ "14. Master's degree [College]",
            as.character(QEDU1ROM) == "15" ~ "15. Doctorate degree [College]",
            
            as.character(QEDU1RUS) == "1" ~ "1. Primary general education or less/ no formal education [Primary]",
            as.character(QEDU1RUS) == "2" ~ "2. 5-9 grades of secondary school (incomplete secondary) [Primary]",
            as.character(QEDU1RUS) == "3" ~ "3. Completed secondary education [Primary]",
            as.character(QEDU1RUS) == "4" ~ "4. Primary professional education [Primary]",
            as.character(QEDU1RUS) == "5" ~ "5. Secondary professional education [Primary]",
            as.character(QEDU1RUS) == "6" ~ "6. Higher education on 1-tier system [Primary]",
            as.character(QEDU1RUS) == "7" ~ "7. Completed college (2-tier system) [College]",
            as.character(QEDU1RUS) == "8" ~ "8. Master's degree [College]",
            as.character(QEDU1RUS) == "9" ~ "9. Academic degree [College]",
            
            as.character(QEDU1SER) == "1" ~ "1. No school (up to four grades) [No education]",
            as.character(QEDU1SER) == "2" ~ "2. Incomplete primary school (grades 4-7) [No education]",
            as.character(QEDU1SER) == "3" ~ "3. Completed primary school (grade 8) [Primary]",
            as.character(QEDU1SER) == "4" ~ "4. Secondary vocational 1-2 years [Primary]",
            as.character(QEDU1SER) == "5" ~ "5. Secondary vocational 3 years [Primary]",
            as.character(QEDU1SER) == "6" ~ "6. Secondary vocational 4 years [Primary]",
            as.character(QEDU1SER) == "7" ~ "7. Secondary orientation (1978-1988) [Primary]",
            as.character(QEDU1SER) == "8" ~ "8. Secondary general (grammar school) [Primary]",
            as.character(QEDU1SER) == "9" ~ "9. Higher schools [Primary]",
            as.character(QEDU1SER) == "10" ~ "10. University: undergraduate studies - Natural and technical sciences [College]",
            as.character(QEDU1SER) == "11" ~ "11. University: undergraduate studies - Social sciences [College]",
            as.character(QEDU1SER) == "12" ~ "12. University: undergraduate studies - Art Academy [College]",
            as.character(QEDU1SER) == "13" ~ "13. Specialized professional studies [College]",
            as.character(QEDU1SER) == "14" ~ "14. Specialized academic studies [College]",
            as.character(QEDU1SER) == "15" ~ "15. University: completed artistic or scientific postgraduate program - Magistrature or Master [College]",
            as.character(QEDU1SER) == "16" ~ "16. Ph.D Obtained [College]",
            
            as.character(QEDU1UKR) == "1" ~ "1. Primary general education or less [Primary]",
            as.character(QEDU1UKR) == "2" ~ "2. Incomplete secondary - 8-9 grades of secondary school [Primary]",
            as.character(QEDU1UKR) == "3" ~ "3. Primary professional, no completed general secondary educati [Primary]",
            as.character(QEDU1UKR) == "4" ~ "4. Completed secondary education [Primary]",
            as.character(QEDU1UKR) == "5" ~ "5. Primary professional, completed general secondary education [Primary]",
            as.character(QEDU1UKR) == "6" ~ "6. Additional education on the base on completed general second [Primary]",
            as.character(QEDU1UKR) == "7" ~ "7. Incomplete high education [Primary]",
            as.character(QEDU1UKR) == "8" ~ "8. Bachelor's degree [College]",
            as.character(QEDU1UKR) == "9" ~ "9. Master's degree or specialist [College]",
            as.character(QEDU1UKR) == "10" ~ "10. Postgraduate/ Academic degree [College]",
            TRUE ~ NA_character_
          ),
    
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            QGEN == 1 ~ 0,
            QGEN == 2 ~ 1,
            TRUE ~ NA_real_),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural = 
          case_when(
            QS8 == 1 | QS8_POL %in% c(1, 2) ~ 0, 
            QS8 == 2 | QS8_POL == 3 ~ 1,
            TRUE ~ NA_real_),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: Q59a; QTEXT: Would you be willing to accept Jews as	members of your family?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Jewish; TYPE: Distance, family",
      
      # original response (as character vector)
        resp_soc_dist_1_original =
          dplyr::recode(
            as.character(Q59a),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode =
          case_when(
            Q59a == 2 ~ 1,
            Q59a == 1 ~ 0,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 2 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_2_qinfo = "NUM: Q59b; QTEXT: Would you be willing to accept Jews as neighbors?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Jewish; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_2_original =
          dplyr::recode(
            as.character(Q59b),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_2_bin_recode =
          case_when(
            Q59b == 2 ~ 1,
            Q59b == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 3 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_3_qinfo = "NUM: Q59c; QTEXT: Would you be willing to accept Jews as	citizens of our country?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Jewish; TYPE: Distance, citizen",
      
      # original response (as character vector)
        resp_soc_dist_3_original =
          dplyr::recode(
            as.character(Q59c),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_3_bin_recode =
          case_when(
            Q59c == 2 ~ 1,
            Q59c == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 4 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_4_qinfo = "NUM: Q60a; QTEXT: Would you be willing to accept Muslims as members of your family?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Muslim; TYPE: Distance, family",
      
      # original response (as character vector)
        resp_soc_dist_4_original =
          dplyr::recode(
            as.character(Q60a),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_4_bin_recode =
          case_when(
            Q60a == 2 ~ 1,
            Q60a == 1 ~ 0,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 5 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_5_qinfo = "NUM: Q60b; QTEXT: Would you be willing to accept Muslims as neighbors?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Muslim; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_5_original =
          dplyr::recode(
            as.character(Q60b),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_5_bin_recode =
          case_when(
            Q60b == 2 ~ 1,
            Q60b == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 6 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_6_qinfo = "NUM: Q60c; QTEXT: Would you be willing to accept Muslims as citizens of our country?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Muslim; TYPE: Distance, citizen",
      
      # original response (as character vector)
        resp_soc_dist_6_original =
          dplyr::recode(
            as.character(Q60c),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_6_bin_recode =
          case_when(
            Q60c == 2 ~ 1,
            Q60c == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 7 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_7_qinfo = "NUM: Q61a; QTEXT: Would you be willing to accept Catholics as members of your family?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Roman Catholic; TYPE: Distance, family",
      
      # original response (as character vector)
        resp_soc_dist_7_original =
          dplyr::recode(
            as.character(Q61a),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_7_bin_recode =
          case_when(
            Q61a == 2 ~ 1,
            Q61a == 1 ~ 0,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 8 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_8_qinfo = "NUM: Q61b; QTEXT: Would you be willing to accept Catholics as neighbors?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Roman Catholic; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_8_original =
          dplyr::recode(
            as.character(Q61b),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_8_bin_recode =
          case_when(
            Q61b == 2 ~ 1,
            Q61b == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 9 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_9_qinfo = "NUM: Q61c; QTEXT: Would you be willing to accept Catholics as citizens of our country?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Roman Catholic; TYPE: Distance, citizen",
      
      # original response (as character vector)
        resp_soc_dist_9_original =
          dplyr::recode(
            as.character(Q61c),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_9_bin_recode =
          case_when(
            Q61c == 2 ~ 1,
            Q61c == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 10 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_10_qinfo = "NUM: Q62A; QTEXT: Would you be willing to accept Orthodox Christians as members of your family?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Orthodox; TYPE: Distance, family",
      
      # original response (as character vector)
        resp_soc_dist_10_original =
          dplyr::recode(
            as.character(Q62A),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_10_bin_recode =
          case_when(
            Q62A == 2 ~ 1,
            Q62A == 1 ~ 0,
            TRUE ~ NA_real_),

    #########################  
    ### SOCIAL DISTANCE 11 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_11_qinfo = "NUM: Q62B; QTEXT: Would you be willing to accept Orthodox Christians as neighbors?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Orthodox; TYPE: Distance, neighbor",
      
      # original response (as character vector)
        resp_soc_dist_11_original =
          dplyr::recode(
            as.character(Q62B),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_11_bin_recode =
          case_when(
            Q62B == 2 ~ 1,
            Q62B == 1 ~ 0,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 12 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_12_qinfo = "NUM: Q62C; QTEXT: Would you be willing to accept Orthodox Christians as citizens of our country?; ROPTIONS: 1 = Yes [=0] + 2 = No [=1]; TARGET: Orthodox; TYPE: Distance, citizen",
      
      # original response (as character vector)
        resp_soc_dist_12_original =
          dplyr::recode(
            as.character(Q62C),
            "3" = NA_character_,
            "98" = NA_character_,
            "99" = NA_character_),            

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_12_bin_recode =
          case_when(
            Q62C == 2 ~ 1,
            Q62C == 1 ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = "NUM: Q5; QTEXT: Generally speaking, would you say that most people can be trusted or that you can't be too careful in dealing with people?; ROPTIONS: 1 = Most people can be trusted [=0] + 2 = Can’t be too careful [=1] + 3 = Other/Depends [=0]",
    
      # original response (as character vector)
        resp_gentrust_original = dplyr::recode(
            as.character(Q5),
            "98" = NA_character_,
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = case_when(
            Q5 %in% c(1, 3) ~ 0,
            Q5 %in% c(2) ~ 1,
            TRUE ~ NA_real_),  
    
    #########################  
    ##### RELIGIOSITY #######  
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: Q44; QTEXT: How important is religion in your life – very important, somewhat important, not too important or not at all important?; ROPTIONS: 1 = Very important + 2 = Somewhat important + 3 = Not too important + 4 = Not at all important",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(Q44),
            "98" = NA_real_,
            "99" = NA_real_),      

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (4 - resp_religiosity_original)/3,
    
    ) %>% 
    select(starts_with("resp_"))
```

# Save data

```{r}
  saveRDS(clean_prbnbcee, "../cleaned-data/y-14-multi-pew-religious-belief-and-national-belonging-in-central-and-eastern-europe.rds")
```